package com.hsgene.user.dto.register;

import com.hsgene.common.util.basic.SimpleRegexUtils;
import com.hsgene.common.util.basic.SimpleStringUtils;
import com.hsgene.common.util.exception.IllegalParamException;
import com.hsgene.common.util.validation.FieldChecker;

import java.io.Serializable;

/**
 * 管理员注册信息
 *
 * @author wangbing
 * @version 1.0, 2018/7/12
 */
public class ManagerRegisterDto implements Serializable {

    private static final long serialVersionUID = 8515929328079724122L;

    /**
     * 供应商id（0表示平台注册用户）
     */
    private Long supplierId;

    /**
     * 账号
     */
    private String userName;

    /**
     * 密码
     */
    private String password;

    /**
     * 注册IP
     */
    private String registerIp;

    public void check() {
        FieldChecker.checkEmpty(supplierId, "supplierId");
        FieldChecker.checkEmpty(userName, "账号");
        boolean isPhoneNumber = SimpleRegexUtils.isMobile(userName) || SimpleRegexUtils.isTelephone(userName);
        if (isPhoneNumber) {
            throw new IllegalParamException("账号名不能为电话号码");
        } else if (SimpleStringUtils.isNumber(userName)) {
            throw new IllegalParamException("账号名不能为纯数字");
        }
        FieldChecker.checkEmpty(password, "密码");
    }

    public Long getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRegisterIp() {
        return registerIp;
    }

    public void setRegisterIp(String registerIp) {
        this.registerIp = registerIp;
    }
}
